﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="原料入出库管理.aspx.cs" Inherits="syc.Store.原料入出库管理" %>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript" language="javascript" src="/common.js"></script>
<form id="form1" runat="server">
<asp:Label ID="SqlText" runat="server" Text="" Visible="false"></asp:Label>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>"
onselected="SqlDataSource1_Selected" 
DeleteCommand="begin transaction;
declare @LastID int,@原料ID int,@入出 tinyint;
select @原料ID=原料ID,@入出=入出 from 原料入出库 with(tablockx) where ID=@ID;
select top 1 @LastID=ID from 原料入出库 where 原料ID=@原料ID and FID=0 order by ID desc;
if @LastID=@ID begin if @入出=0 begin
update 原料到货记录 set 入库单ID=0 where 入库单ID=@ID;end;
else if @入出=1 begin update 原料发货记录 set 出库单ID=0 where 出库单ID=@ID;end;
delete from 原料入出库 where ID=@ID or FID=@ID; end commit">
<DeleteParameters>
<asp:Parameter Name="ID" DbType="Int32" Size="4"/>
</DeleteParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
SelectCommand="select 0 as ID,'全部' as 名称 union all select ID, 名称 FROM 原料供货单位"></asp:SqlDataSource>

<div id="wintop" class="wintop">原料入出库管理</div>

<asp:Panel ID="Panel1" runat="server" CssClass="panel">
    
    <asp:Button ID="Button_InBill" runat="server" Text="入库单录入" CssClass="button"  
        UseSubmitBehavior="False" OnClientClick="parent.swin2_load('/Store/原料入库单录入.aspx',770,440);"/>
        
    <asp:Button ID="Button_OutBill" runat="server" Text="出库单录入" CssClass="button"  
        UseSubmitBehavior="False" OnClientClick="parent.swin2_load('/Store/原料出库单录入.aspx',770,440);"/>
        
    <asp:Button ID="Button_Edit" runat="server" Text="查 看" CssClass="button"  
        UseSubmitBehavior="False" Enabled="false"/>

    <asp:Button ID="Button_Detail" runat="server" Text="到发记录" CssClass="button"  
        UseSubmitBehavior="False" Enabled="false"/>

    <asp:Button ID="Button_Delete" runat="server" Text="删 除" CssClass="button"  
        UseSubmitBehavior="False" 
        onclick="Button_Delete_Click"
        OnClientClick="if(!confirm('确认要删除该条记录吗？'))return(false);" />
</asp:Panel>

<asp:Panel ID="Panel2" runat="server" CssClass="panel" GroupingText="原料入出库查询">

<!-- =================================================================================================== -->
<!-- ========                               原料类别列表                                     =========== -->
<!-- ========                                                                               =========== -->
<!-- =================================================================================================== -->
<asp:SqlDataSource ID="DS_LeiBie" runat="server" 
                   ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
                    SelectCommand="SELECT [ID],[品名]+' '+[钢级]+' '+[规格] AS 名称 FROM [原料]" >
</asp:SqlDataSource>
原料：
<asp:DropDownList ID="LeiBie" runat="server" Width="250px" Font-Size="12px" DataSourceID="DS_LeiBie" 
                               DataTextField="名称" DataValueField="ID">
</asp:DropDownList>
<!-- =================================================================================================== -->


<span style="margin-left:10px;"></span>使用单位：<asp:DropDownList ID="FenChang" Width="120px"
    runat="server">
    <asp:ListItem Text="全部" Value="0"></asp:ListItem>
    <asp:ListItem Text="一分厂" Value="1"></asp:ListItem>
    <asp:ListItem Text="二分厂" Value="2"></asp:ListItem>
    <asp:ListItem Text="三分厂" Value="3"></asp:ListItem>
    <asp:ListItem Text="四分厂" Value="4"></asp:ListItem>
    <asp:ListItem Text="五分厂" Value="5"></asp:ListItem>
</asp:DropDownList>

<span style="margin-left:10px;"></span>供货单位：<asp:DropDownList 
    ID="GongHuo" runat="server" DataSourceID="SqlDataSource2"  Width="120px"
    DataTextField="名称" DataValueField="ID"></asp:DropDownList>
    
<span style="margin-left:12px;"></span><asp:Button ID="Button_Export" 
        runat="server" Text="导出明细账..." UseSubmitBehavior="false"  Visible="true"
        CssClass="mbutton2" onclick="Button_Export_Click" />
        

        
<div style="font-size:6px;height:6px;line-height:6px;"></div>
显示筛选：<asp:DropDownList ID="XianShi" runat="server" Width="160px">
<asp:ListItem Value="">全部显示</asp:ListItem>
<asp:ListItem Value="0">仅显示入库单</asp:ListItem>
<asp:ListItem Value="1">仅显示出库单</asp:ListItem>
</asp:DropDownList>
    
<span style="margin-left:10px;"></span>起始日期：<asp:TextBox ID="Date1" runat="server" CssClass="textbox" Width="105px"></asp:TextBox><img alt="" src="/Icons/29.png" align="middle" onclick="makecalendar(document.getElementById('Date1').value, document.getElementById('Date1'));" />
<span style="margin-left:10px;"></span>截止日期：<asp:TextBox ID="Date2" runat="server" CssClass="textbox" Width="105px"></asp:TextBox><img alt="" src="/Icons/29.png" align="middle" onclick="makecalendar(document.getElementById('Date2').value, document.getElementById('Date2'));" />

<span style="margin-left:10px;"></span><asp:Button ID="Button_Query" runat="server" Text="查 询" UseSubmitBehavior="false" 
        CssClass="mbutton" onclick="Button_Query_Click" />
<asp:Button ID="Button_Reset" runat="server" Text="清空条件" UseSubmitBehavior="false" 
        CssClass="mbutton" onclick="Button_Reset_Click" />
</asp:Panel>


<div class="gridframe">
    <div class="gridview">
    
        <table border="1" width="100%" cellspacing="0" cellpadding="0" bordercolor="#e5cfab">
            <tr>
	            <td class="grid-title">原料入出库记录</td>
	        </tr>
	        <tr>
	            <td class="grid-back">
                    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                        AutoGenerateColumns="False" CssClass="grid" DataKeyNames="ID,入出,FID" 
                        DataSourceID="SqlDataSource1"
                        PageSize="30"
                        GridLines="None" ondatabound="GridView1_DataBound" 
                        onpageindexchanged="GridView1_PageIndexChanged" AllowSorting="True" 
                        UseAccessibleHeader="False" 
                        onselectedindexchanged="GridView1_SelectedIndexChanged" >
                        <PagerSettings Visible="False" />
                        <RowStyle CssClass="grid-row-normal" />
                        <Columns>
                            <asp:TemplateField HeaderText="">
                                <ItemTemplate>
                                    <asp:Button ID="Button_xz" runat="server" CommandName="Select" Text="选择" CssClass="hide"/>
                                    <asp:Image ID="Image_icon" runat="server" ImageUrl="/Icons/online.gif" />
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="20px" />
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="入出">
                                <ItemTemplate>
                                    <img src='/Images/io-<%# Eval("入出") %>.png' />
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="30px" />
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText="单据号">
                                <ItemTemplate>
                                    <asp:Label ID="Label_djh" runat="server" Text='<%# Eval("单据号","{0:D7}") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="50px" />
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText="供货或使用">
                                <ItemTemplate>
                                    <asp:Label ID="Label_gy" runat="server" Text='<%# Eval("供货或使用") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="100px" />
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText="品名" SortExpression="原料ID">
                                <ItemTemplate>
                                    <asp:Label ID="Label_pm" runat="server" Text='<%# Eval("品名") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="100px" />
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText="规格" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="Label_gg" runat="server" Text='<%# Eval("规格") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="100px" />
                            </asp:TemplateField>
                                                        
                            <asp:TemplateField HeaderText="重量(吨)">
                                <ItemTemplate>
                                    <asp:Label ID="Label_zl" runat="server" Text='<%# Eval("重量") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="right" Width="60px" />
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText="支数">
                                <ItemTemplate>
                                    <asp:Label ID="Label_zs" runat="server" Text='<%# Eval("支数") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="center" Width="60px" />
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText="单价" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="Label_dj" runat="server" Text='<%# Eval("单价","{0:0.00}") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="right" Width="60px" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="金额">
                                <ItemTemplate>
                                    <asp:Label ID="Label_je" runat="server" Text='<%# Eval("金额","{0:0.00}") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="right" Width="70px" />
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText="结存重量">
                                <ItemTemplate>
                                    <asp:Label ID="Label_jczl" runat="server" Text='<%# Eval("结存重量") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="right" Width="80px" />
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText="结存支数">
                                <ItemTemplate>
                                    <asp:Label ID="Label_jczs" runat="server" Text='<%# Eval("结存支数") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="center" Width="70px" />
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText="结存金额">
                                <ItemTemplate>
                                    <asp:Label ID="Label_jcje" runat="server" Text='<%# Eval("结存金额","{0:0.00}") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="right" Width="80px" />
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText="日期" SortExpression="日期">
                                <ItemTemplate>
                                    <asp:Label ID="Label_rq" runat="server" Text='<%# Eval("日期","{0:d}") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="60px" />
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText="保管员">
                                <ItemTemplate>
                                    <asp:Label ID="Label_bgy" runat="server" Text='<%# Eval("保管员") %>'></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="60px" />
                            </asp:TemplateField>
                           
                        </Columns>
                        <SelectedRowStyle CssClass="grid-row-selected" />
                      </asp:GridView>
	            </td>
            </tr>
            <tr>
	            <td>   
	                <table width="100%">
	                    <tr>
	                        <td class="pagebar">
                                <asp:Button ID="Button_Pager_First" UseSubmitBehavior="false" runat="server" Text="" ToolTip="首页" 
                                    CssClass="pageturn-first-b" onclick="Pager_Click" CommandName="--" />
                                <asp:Button ID="Button_Pager_Prev" UseSubmitBehavior="false" runat="server" Text="" ToolTip="上一页" 
                                    CssClass="pageturn-prev-b" onclick="Pager_Click" CommandName="-" />
                                <input type="button" class="page-split" UseSubmitBehavior="false" disabled />第<asp:TextBox 
                                    ID="TextBox_Pager" AutoPostBack="True" runat="server" CssClass="pageturn" 
                                    ontextchanged="Pager_Click"></asp:TextBox>页<input type="button" class="page-split" disabled /><asp:Label ID="Label_Pages" UseSubmitBehavior="false" runat="server"></asp:Label><input type="button" class="page-split" disabled />
                                
                                <asp:Button ID="Button_Pager_Next" UseSubmitBehavior="false" runat="server" Text="" ToolTip="下一页" 
                                    CssClass="pageturn-next-b" onclick="Pager_Click" CommandName="+" />
                                <asp:Button ID="Button_Pager_Last" UseSubmitBehavior="false" runat="server" Text="" ToolTip="末页" 
                                    CssClass="pageturn-last-b" onclick="Pager_Click" CommandName="++" /><asp:Label ID="Label9" runat="server"></asp:Label><input type="button" class="page-split" disabled />
                            </td>
                            <td class="pagebar" align="right">
                                <asp:Label ID="Label_Total" runat="server"></asp:Label>
                            </td>
                        </tr>
                   </table>

	            </td>
            </tr>
        </table>
        

    </div>
</div>

</form>
<script>
    var notice = '<%=this.Notice %>';
    if (notice != '') {
        parent.showmsgbox(notice);
    }
    var textboxs = document.getElementsByTagName("input");
    var i;
    for (i = 0; i < textboxs.length; i++) {
        if (textboxs[i].className == "textbox") {
            //textboxs[i].onchange = function(e) { this.className = "textbox-changed"; };
            textboxs[i].onfocus = function(e) { this.select(); };
        }
        else if (textboxs[i].className == "pageturn" || textboxs[i].className == "intxt1" || textboxs[i].className == "intxt2") {
            textboxs[i].onfocus = function(e) { this.select(); };
        }
    }
    var rows = document.getElementsByTagName("tr");
    for (i = 0; i < rows.length; i++) {

        if (rows[i].className == "grid-row-normal") {
            rows[i].onmouseover = function() { this.className = "grid-row-bright"; };
            rows[i].onmouseout = function() { this.className = "grid-row-normal"; };
            rows[i].onclick = selectRow;
        }
    }

    document.onkeydown = function(e) {
        if (!e) e = window.event;
        var tag = e.srcElement;
        if (!tag) tag = e.target;
        if (tag.tagName == "INPUT" && tag.className == "textbox" || tag.tagName == "SELECT") {
            if (e.keyCode == 13) e.keyCode = 9;
        }
    }
    var rows = document.getElementById("GridView1").rows;
    var sum1 = 0, sum2 = 0, sum3=0;
    var col = 5;
    for (i = 1; i < rows.length; i++) {
        sum1 += Number(rows[i].cells[col].innerText);
        sum2 += Number(rows[i].cells[col + 1].innerText);
        sum3 += Number((rows[i].cells[col + 2].innerText)*1000);
    }
    var total = document.getElementById("Label_Total");
    total.innerHTML += "　　本页小计：" + (rows.length - 1) + " 项 " + fixFloatZ(sum1, 3) + " 吨 " + sum2 + " 支 " + sum3/1000 + " 元";
    
</script>
</body>
</html>
